/**
 * 
 */
package org.gigi.security.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 * 用户组
 * 
 * 一组用户，组中的所有用户具有相同的权限。
 * 
 * @author Eugene Wang 2011-8-29
 * @see
 */
@Entity
@Table(name = "sec_group")
public class Group implements Serializable {
	private static final long serialVersionUID = 1L;

	//虚拟的根节点对应ID值
	public static final long ROOT_ID = 0l;

	@Id
	@TableGenerator(name = "group_gen", table = "id_generater", pkColumnName = "gen_name", valueColumnName = "gen_value", pkColumnValue="sec_group")
	@GeneratedValue(generator = "group_gen", strategy=GenerationType.TABLE)
	private long id;
	private String name;
	@Column(name="layer_order")
	private int layerOrder;
	@ManyToOne
	@JoinColumn(name = "parent_id")
	private Group parent;

	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="sec_rl_group_authority", joinColumns=@JoinColumn(name="group_id"), inverseJoinColumns=@JoinColumn(name="authority"))
	@Basic(fetch=FetchType.LAZY)
	private Set<Authority> authorities;

	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getLayerOrder() {
		return layerOrder;
	}
	public void setLayerOrder(int layerOrder) {
		this.layerOrder = layerOrder;
	}
	public Group getParent() {
		return parent;
	}
	public void setParent(Group parent) {
		this.parent = parent;
	}
	public Set<Authority> getAuthorities() {
		return authorities;
	}
	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}
}
